<template>
  <view class="content">
    <u-sticky
      style="height: 110upx;"
      bg-color="#F8F9FC">
      <view
        class="topsearch x-row fff">
        <view
          class="x-col-center x-col">
          <view
            class="search">
            <u-search
              placeholder="请输入搜索客户名称"
              shape="square"
              bg-color="#fff"
              :show-action="false"
              height="70"
              @change="changeSearch"
              :value="keywords">
            </u-search>
          </view>
        </view>
        <view
          @click="gotoBack"
          class="x-col-center"
          style="padding:0 30upx;border-left: 1px solid #D8D8D8;">
          <view class="x-row">
            <image
              :src="img+'mapicon_sd.png'"
              class="mapimg"
              mode="widthFix">
            </image>
            <view
              class="titel">
              地图查看</view>
          </view>
        </view>
      </view>
    </u-sticky>
    <order-list :list="clist">
    </order-list>
    <u-empty text="暂无数据"
      mode="list"
      v-if="!clist.length">
    </u-empty>
    <block
      v-if="userType=='xs'">
      <view
        style="height: 144upx; width: 100%;">
      </view>
      <view class="buttonAdd"
        @click="gotoPage('../sale/add_customer')">
        添加客户</view>
      <u-action-sheet
        :list="list"
        v-model="show"
        @click="onSheet"
        :safe-area-inset-bottom="true">
      </u-action-sheet>
    </block>
  </view>
</template>

<script>
import orderList from '@/components/order-list'
export default {
  components: { orderList },
  data() {
    return {
      show: false,
      img: this.urlimg + 'mini/',
      list: [
        {
          text: '添加拜访'
        },
        {
          text: '拜访记录'
        },
        {
          text: '应收账单'
        }
      ],
      keywords: '',
      from: '', //来源 index 首页，map 地图线路
      clist: [],
      li: '',
      userType: 'xs' //默认销售xs
    }
  },
  onLoad(e) {
    this.from = e.from ? e.from : ''

    uni.setNavigationBarTitle({
      title: e.from == 'map' ? '我的线路' : '我的客户'
    })
    this.userType = uni.getStorageSync('userType')
    this.init()
  },
  methods: {
    getOrder(e) {
      // 司机线路图的时候，需要跳转到商家的订单页面
      if (this.userType == 'sj') {
        this.$api.navigator('../driver/sendOrder?id=' + e.id + '&bid=' + e.bid)
      }
    },
    changeSearch() {
      this.getlist()
    },
    init() {
      this.getlist()
    },
    keyIpt(e) {
      this.keywords = e.detail.value
      this.getlist()
    },
    gotoBack() {
      uni.navigateBack({})
    },
    cellPhone(e) {
      uni.makePhoneCall({
        phoneNumber: e.business.phone
      })
    },
    toStore(e) {
      uni.openLocation({
        //​使用微信内置地图查看位置。
        latitude: parseFloat(e.business.lat), //要去的纬度-地址
        longitude: parseFloat(e.business.lon), //要去的经度-地址
        name: e.business.map_address
      })
    },
    gotoPage(url) {
      this.$api.navigator(url)
    },
    clickMsg(li) {
      this.li = li
      this.show = true
    },
    // user/route 			我的路线
    getlist() {
      let that = this
      this.$axios(this.userType == 'xs' ? 'user/route' : 'user/droute', {
        keywords: this.keywords
      }).then(res => {
        that.clist = res.result
        // that.customer=data[0]
        that.loading = false
      })
    },
    onSheet(e) {
      switch (e) {
        case 0:
          uni.removeStorageSync('ec_imgs')
          uni.removeStorageSync('ex_imgs')
          uni.navigateTo({
            url: '../sale/addvisitrecord?cid=' + this.li.id
          })
          break
        case 1:
          uni.navigateTo({
            url: '../sale/visit_records?key=' + this.li.bname
          })
          break
        case 2:
          uni.navigateTo({
            url: '../sale/my_bill?key=' + this.li.bname
          })
          break
      }
    }
  }
}
</script>